package com.andy.qhb.conf;
 
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import com.andy.qhb.QhbApplication;
import com.andy.qhb.dao.DbBatch;
import com.andy.qhb.game.GameConf;
import com.andy.qhb.game.Global;
import com.andy.qhb.game.GlobalHttp;
import com.andy.qhb.game.task.TimerManager;

/**
 * 初始化和销毁处理
 * @author andy
 *
 */
@Component
public class InitAndDestroy implements InitializingBean, DisposableBean {
 
	@Override
	public void afterPropertiesSet() throws Exception {
		// 初始化配置
    	GameConf.init();
    	
    	GlobalHttp.initUsers();
    	
    	Global.getGroups();
    	
    	TimerManager.init();
    	
    	// 启动db线程
    	DbBatch.start(2);
    	
	}
 
	@PreDestroy
	public void preDestroy() {
		System.out.println("开始停止服务器...");
		QhbApplication.ServerStatus = 2;
		DbBatch.stopBatch();
		System.out.println("停止服务器完成...");
	}
	
	
	@Override
	public void destroy() throws Exception {
		System.out.println("接口-执行InitBeanAndDestroyBeanTest：destroy方法");
	}

 
}
